import { fileURLToPath, URL } from 'node:url'
import { defineConfig, loadEnv } from 'vite'
import vue from '@vitejs/plugin-vue'
import Components from 'unplugin-vue-components/vite'
import { VantResolver } from 'unplugin-vue-components/resolvers'

// https://vitejs.dev/config/
export default defineConfig(({mode}) => {
  const env = loadEnv(mode, process.cwd());
  console.log(env.VITE_BASE_PATH)
  return {
    base: env.VITE_BASE_PATH,//域名下的范围目录如：http://*******/flop
    server:{
      host:'0.0.0.0',
      port:8001, // 启动端口号
      open:true,  // 启动后是否自动打开网页
      proxy: {
        "/api": {
          target:"https://www.biaoshitong.com",
          changeOrigin: true,
          ws: true,
          rewrite: (path) => path.replace(/^\/api/, '')
        }
      }
    },
    plugins: [
      vue(),
      Components({ resolvers: [VantResolver()] })
    ],
    resolve: {
      alias: {
        '@': fileURLToPath(new URL('./src', import.meta.url))
      }
    }
  }
  
})
